﻿using UnityEngine;

[AddComponentMenu("MyGame/SuperEnemy")]
public class SuperEnemy : Enemy
{

    public Transform m_rocket;

    protected float m_fireTimer = 1;
    protected Transform m_player;

    void Awake()
    {
        GameObject obj = GameObject.FindGameObjectWithTag("Player");
        if (obj != null)
        {
            m_player = obj.transform;
        }
    }

    protected override void UpdateMove()
    {
        m_fireTimer -= Time.deltaTime;
        if (m_fireTimer <= 0)
        {
            m_fireTimer = 1;
            if (m_player != null)
            {
                Vector3 relativePos = m_transform.position - m_player.position;
                Instantiate(m_rocket, m_transform.position, Quaternion.LookRotation(relativePos));
                m_audio.PlayOneShot(m_shootClip);
            }
        }
        m_transform.Translate(new Vector3(0, 0, -m_speed * Time.deltaTime));
    }
}
